package com.jluzh.filter;

import javax.ws.rs.client.ClientRequestContext;
import javax.ws.rs.client.ClientRequestFilter;
import javax.ws.rs.core.Response;
import java.io.IOException;

/**
 * @author EvanHuang
 * @date 11/5/2018 9:35 PM
 * @since
 */
// 客户端过滤器
public class CheckRequestFilter implements ClientRequestFilter {
    @Override
    public void filter(ClientRequestContext requestContext) throws IOException {
        if (requestContext.getHeaders().get("Client-Name") == null) {
            requestContext.abortWith(
                    Response.status(Response.Status.BAD_REQUEST)
                            .entity("Client-Name header must be defined.")
                            .build());
        }

    }
}
